package com.fqcar.fqdf.plugin.image;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.TextView;

import com.baidu.mapapi.navi.BaiduMapAppNotSupportNaviException;
import com.baidu.mapapi.navi.BaiduMapNavigation;
import com.baidu.mapapi.navi.NaviParaOption;
import com.fqcar.fqdf.R;
import com.fqcar.fqdf.core.BaseStatisticsActivity;
import com.fqdf.framework.android.util.AndroidUtils;
import com.fqdf.framework.android.util.Constants;
import com.fqdf.framework.android.util.DialogUtil;
import com.rd.PageIndicatorView;
import com.rd.animation.type.AnimationType;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ImageZoomActivity extends BaseStatisticsActivity {

    @BindView(R.id.image_zoom_viewpage)
    ViewPager imageZoomViewpage;
    @BindView(R.id.page_indicator_view)
    PageIndicatorView pageIndicatorView;
    @BindView(R.id.baidu_ar_nav)
    TextView baiduArNav;

    private ImagePagerAdapter mAdapter;
    private List<ImageZoomBean> dataList;
//    private BaiduArNavBean baiduArNavBean;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_image_zoom);
        ButterKnife.bind(this);
        Bundle bundle = getIntent().getExtras();
        dataList = bundle.getParcelableArrayList(Constants.BUNDLE_DATA);
//        if (bundle.containsKey(Constants.BUNDLE_DATA_EXT)) {
//            baiduArNavBean = bundle.getParcelable(Constants.BUNDLE_DATA_EXT);
//        }
        initView();
    }

    private void initView() {

        if (AndroidUtils.isSupportVersion(21)) {
            getWindow().setAllowEnterTransitionOverlap(false);
            getWindow().setAllowReturnTransitionOverlap(false);
        }

        mAdapter = new ImagePagerAdapter(this, dataList) {
            @Override
            public void clickItemListener(ImageZoomBean item) {
                if (AndroidUtils.isSupportVersion(21)) {
                    finishAfterTransition();
                } else {
                    finish();
                }
            }
        };
        imageZoomViewpage.setAdapter(mAdapter);
        imageZoomViewpage.setOffscreenPageLimit(3);

        pageIndicatorView.setViewPager(imageZoomViewpage);
        pageIndicatorView.setAnimationType(AnimationType.SLIDE);

//        baiduArNav.setVisibility(baiduArNavBean != null ? View.VISIBLE : View.GONE);

    }

    /*@OnClick(R.id.baidu_ar_nav)
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.baidu_ar_nav:
                startWalkingNaviAR(baiduArNavBean);
                break;
            default:
                break;
        }
    }*/

    /**
     * 启动百度地图步行AR导航(Native)
     */
    public void startWalkingNaviAR(BaiduArNavBean navBean) {

        // 构建 导航参数
        NaviParaOption para = new NaviParaOption()
                .startPoint(navBean.getStartLocation()).endPoint(navBean.getEndLocation())
                .startName(navBean.getStartName()).endName(navBean.getEndName());

        try {
            BaiduMapNavigation.openBaiduMapWalkNaviAR(para, this);
        } catch (BaiduMapAppNotSupportNaviException e) {
            e.printStackTrace();
            DialogUtil.creatBaseDialog(this, "您尚未安装百度地图app或app版本过低");
        }

    }
}
